<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<link rel="stylesheet" href="../style/journal.css" type="text/css" />
<style type="text/css"><!--
.googleadsense {
	margin: 2px;
	padding: 0px;
//--></style><script src="http://www.google-analytics.com/urchin.js" type="text/javascript">
</script>
<script type="text/javascript">
_uacct = "UA-65008-1";
urchinTracker();
</script><title>Win32 下 Apache 和 #!/usr/bin/perl</title>
</head>
<body>
<a href="index.html">Journal</a>(2005) | <a href="../blog/"><b>Blog</b></a>(2006) | <a href="http://www.fayland.org/cgi-bin/random_link.pl">RandomLink</a> | <a href="AboutFayland.html">WhoAmI</a> | <a href="LiveBookmark.html">LiveBookmark</a> | <a href="http://www.fayland.org/">HomePage</a>
<p><&lt;Previous: <a href="050330.html">Class::DBI 改 Primary 项</a>&nbsp;&nbsp;>>Next: <a href="minicpan.html">如何用 minicpan 映像自己的 CPAN</a></p>
<h1>Win32 下 Apache 和 #!/usr/bin/perl</h1>
<div class='content'>
<p>Category: <a href='Basic.html'>Basic</a> &nbsp; Keywords: <b>#!/usr/bin/perl</b></p>我一向喜欢写
<pre>#!/usr/bin/perl</pre>
这么写的很大部分原因是为了兼容 Linux(Unix).<p>

但是假设你的 Perl 目录为 C:\usr\bin, 而 Apache 目录为 D:\Apache2.
那你所有的程序头一行必须是
<ol>
<li>#!C:/usr/bin/perl.exe
<li>#!usr/bin/perl
<li>#!perl
</ol>
这三种中的一种。其中第 3 种还必须得把 C:\usr\bin 加个 Path 中。<br>
如果你不这么做，当你访问类如 http://localhost/cgi-bin/printenv.pl（此程序以#!/usr/bin/perl开头时） 时就会报错：
<pre>No such file or directory: couldn't spawn child process: D:/Apache2/cgi-bin/printenv.pl</pre>
<p>
解决这个问题的方法不是修改 httpd.conf 或者注册表什么的。你要么都用 #!C:/usr/bin/perl.exe 开头，要么将 Apache 和 Perl 安装到一个目录中（都在 C: 或者都在 D:）<p>

今天重装 Apache 时发现此问题。按照搜索来的修改 httpd.conf 和注册表或文件对应都没用，后来火大再重装回 C:\Apache2 时无意中解决。希望能有所帮助。我的配置为：
<pre><a href='http://www.perl.org'>Perl</a> 5.8.6 and <a href='http://httpd.apache.org'>Apache</a> 2.0.52, together with <a href='http://perl.apache.org'>mod_perl</a>-1.99_20, mod_ssl / OpenSSL (0.9.7e), and <a href='http://www.php.net'>php-4.3.10</a></pre>
</div>
<p><&lt;Previous: <a href="050330.html">Class::DBI 改 Primary 项</a>&nbsp;&nbsp;>>Next: <a href="minicpan.html">如何用 minicpan 映像自己的 CPAN</a></p>
<p><strong>Options:</strong> <a href='http://del.icio.us/post?title=Win32%20%E4%B8%8B%20Apache%20%E5%92%8C%20%23!/usr/bin/perl&url=http://www.fayland.org/journal/050401.html'>+Del.icio.us</a></p>
<strong>Related items</strong>
<ul><li><a href='ShareURL0503.html'>Share the URLs with u (Mar. 2005)</a> < <span class='digit'>2005-03-08 00:36:53</span> ></li><li><a href='ShareURL0506.html'>Share the URLs (June 2005)</a> < <span class='digit'>2005-06-01 23:51:11</span> ></li><li><a href='ShareURL0504.html'>Share the URLs with u (Apr. 2005)</a> < <span class='digit'>2005-04-01 10:18:51</span> ></li><li><a href='ShareURL0505.html'>Share the URLs with u (May 2005)</a> < <span class='digit'>2005-05-10 22:16:17</span> ></li><li><a href='ShareURL0509.html'>Share the URLs (September 2005)</a> < <span class='digit'>2005-09-22 12:29:39</span> ></li><li><a href='ShareURL0510.html'>Share the URLs (October 2005)</a> < <span class='digit'>2005-10-08 10:38:10</span> ></li><li><a href='ShareURL0512.html'>Share the URLs (December 2005)</a> < <span class='digit'>2005-12-01 00:13:53</span> ></li></ul>
Created on <span class="digit">2005-04-01 10:10:59</span><br />
Copyright 2004-2005 All Rights Reserved. Powered by <a href="Eplanet.html">Eplanet</a> && <a href='http://catalyst.perl.org'>Catalyst</a> 5.62.
</body>
</html>